const Generator = require('yeoman-generator')

module.exports = class extends Generator {
    prompting() {
        return this.prompt(([
            {
                type: 'input',
                name: 'title',
                message: 'file number start-end?', // 例：1-36
                default: this.appname, // 项目生成名称
            }
        ])).then(answers => {
            this.answers = answers
        })
    }

    writing() {
        const numArr = this.answers.title.split('-')
        let start = parseInt(numArr[0])
        const end = parseInt(numArr[1])
        const fileNames = []

        while(start <= end) {
            fileNames.push(start)
            start++
        }
        
        const tpl = this.templatePath('blog.html')

        fileNames.forEach(num => {
            const output = this.destinationPath(`blog-${num}.html`)
            const context = {}

            this.fs.copyTpl(tpl, output, context)
        })
    }
}